﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using EQEmu.Database;

namespace EQEmu.Grids
{
    public class GridDatabase : Grid
    {
        private EQEmuContext _context = null;

        public GridDatabase(grid grid,EQEmuContext context)
            : base(grid)
        {
            _context = context;
            var entries = context.grid_entries.Where(x => x.zoneid == grid.zoneid && x.gridid == grid.id);
            foreach (var entry in entries)
            {
                _entries.Add(entry);
            }
        }

        public override void AddEntry(grid_entries entry)
        {
            base.AddEntry(entry);
            _context.grid_entries.AddObject(entry);
        }

        public override void RemoveEntry(grid_entries entry)
        {
            base.RemoveEntry(entry);
            _context.grid_entries.DeleteObject(entry);
        }
    }
}
